package com.example.AdminComponent;


import com.example.Utils.HttpUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.HashMap;
import java.util.Map;

public class addTeacherJFrame extends JFrame {
    public addTeacherJFrame() {
        super.setTitle("修改");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        setVisible(true);
        setSize(400, 300);
        JPanel jPanel = new JPanel();
        Box big = Box.createVerticalBox();
        //确定按钮
        JButton b1 = new JButton("确定");
        //取消按钮
        JButton b2 = new JButton("取消");
        //退出按钮
        //学号
        Box idBox = Box.createHorizontalBox();
        JLabel idLabel = new JLabel("工号");
        JTextField idText = new JTextField();
        idBox.add(idLabel);
        idBox.add(Box.createHorizontalStrut(10));
        idBox.add(idText);
        //姓名
        BoxUlit nameBox = new BoxUlit("姓名");
        //学院
        BoxUlit aaClassBox = new BoxUlit("学院");
        big.add(Box.createVerticalStrut(30));
        big.add(idBox);
        big.add(Box.createVerticalStrut(5));
        big.add(nameBox);
        big.add(Box.createVerticalStrut(5));
        big.add(aaClassBox);
        big.add(Box.createVerticalStrut(25));
        Box buttons = Box.createHorizontalBox();
        buttons.add(b1);
        buttons.add(Box.createHorizontalStrut(40));
        buttons.add(b2);
        big.add(buttons);
        jPanel.add(big);
        add(jPanel);
        //取消事件
        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
            }
        });

        //确定事件
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Map<String, String> map = new HashMap<>();
                map.put("id", idText.getText());
                map.put("name", nameBox.idText.getText());
                map.put("department", aaClassBox.idText.getText());
                HttpUtil.sendPost("http://localhost:8080/teacher/insert", map);
                JOptionPane.showMessageDialog(null, "修改成功！点击查询刷新数据");
                dispose();
            }
        });
    }
}
